package xml;

import java.awt.*;
import javax.xml.bind.annotation.adapters.XmlAdapter;

public class RectangleAdapter extends XmlAdapter<RectangleType, Rectangle> {
	
	public RectangleType marshal(Rectangle rectangle) throws Exception {
		RectangleType rectType = new RectangleType();
		rectType.setX(rectangle.x);
		rectType.setY(rectangle.y);
		rectType.setWidth(rectangle.width);
		rectType.setHeight(rectangle.height);

		return rectType;
	}

	// reverse operation: map XML type to Java
	public Rectangle unmarshal(RectangleType rectType) throws Exception { 
		Rectangle rect = new Rectangle();
		rect.x = rectType.getX();
		rect.y = rectType.getY();
		rect.width = rectType.getWidth();
		rect.height = rectType.getHeight();
        
        return rect;
	}
}